package com.example.myapplication.tack_04.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.myapplication.R;
import com.example.myapplication.tack_04.PageStop;
import com.example.myapplication.tack_04.Stop;
import com.example.myapplication.tack_04.data.StopData;
import com.example.myapplication.utils.Common;

import java.util.List;

public class StopAdatert extends RecyclerView.Adapter<StopAdatert.My> {
    private List<StopData.RowsDTO> list;
    private Context context;
    private View view;

    public StopAdatert(List<StopData.RowsDTO> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @NonNull
    @Override
    public My onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        view = LayoutInflater.from(context).inflate(R.layout.list,null);
        return new My(view);
    }

    @Override
    public void onBindViewHolder(@NonNull My holder, int position) {
        holder.parkName.setText(list.get(position).getParkName());
        holder.address.setText(list.get(position).getAddress());
        holder.vacancy.setText("空位个数"+list.get(position).getVacancy());
        holder.rates.setText("收费:"+list.get(position).getRates()+"￥");
        holder.list_.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, PageStop.class);
                String str = String.valueOf(list.get(position).getId());
                intent.putExtra(Common.COMMON,str);
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return list != null ?list.size():0;
    }

    public class My extends  RecyclerView.ViewHolder{
        private TextView parkName;
        private TextView address;
        private TextView vacancy;
        private TextView rates;
        private LinearLayout list_;
        public My(@NonNull View itemView) {
            super(itemView);
            parkName = view.findViewById(R.id.parkName);
            address = view.findViewById(R.id.address);
            vacancy = view.findViewById(R.id.vacancy);
            rates = view.findViewById(R.id.rates);
            list_ = view.findViewById(R.id.list);
        }
    }

}
